package com.qf.utils;

import javax.servlet.http.Cookie;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class CookieUtils {

    public static Cookie createCookie(String name,String value,int time){

        Cookie cookie = null;
        try {
            //注意：数据有中文必须设置编码格式
            cookie = new Cookie(name, URLEncoder.encode(value,"UTF-8"));
            cookie.setMaxAge(time);
            return cookie;
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
    }
}
